package com.getpebble.android.framework;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.getpebble.android.R;
import com.getpebble.android.common.core.trace.AnalyticsLogger;
import com.getpebble.android.common.core.trace.AnalyticsLogger.Event;
import com.getpebble.android.common.core.trace.AnalyticsLogger.InitializationException;
import com.getpebble.android.common.core.trace.AndroidLogger;
import com.getpebble.android.common.core.trace.Trace;
import com.getpebble.android.common.core.util.PblPreferences;
import com.getpebble.android.common.core.util.PblPreferences.PrefKey;
import com.getpebble.android.common.model.FrameworkState;
import com.getpebble.android.common.model.FrameworkState.StateListener;
import com.getpebble.android.common.model.PblDevice;
import com.getpebble.android.common.model.PblDeviceModel;
import com.getpebble.android.framework.DeviceInterfaces.IAdapterQuery;
import com.getpebble.android.framework.DeviceInterfaces.IAdapterQueryCallback;
import com.getpebble.android.framework.DeviceInterfaces.IDeviceConnector;
import com.getpebble.android.framework.DeviceInterfaces.IDeviceFetcher;
import com.getpebble.android.framework.DeviceInterfaces.IDeviceMessageSender;
import com.getpebble.android.framework.comm.MessageRouter;
import com.getpebble.android.framework.connectionstate.ConnectionStateManager;
import com.getpebble.android.framework.connectionstate.ConnectionStateManager.ConnectionGoalUpdater;
import com.getpebble.android.framework.connectionstate.ConnectionStateManager.PublicConnectionStatusUpdater;
import com.getpebble.android.framework.developer.DebugConnection;
import com.getpebble.android.framework.developer.DeveloperConnectionClient;
import com.getpebble.android.framework.developer.DeveloperConnectionServer;
import com.getpebble.android.framework.discovery.DiscoveryManager;
import com.getpebble.android.framework.endpoint.EndpointRequest;
import com.getpebble.android.framework.endpoint.EndpointRequest.EndpointAction;
import com.getpebble.android.framework.endpoint.EndpointRequest.EndpointArgumentKeys;
import com.getpebble.android.framework.install.app.AppBundleManager;
import com.getpebble.android.framework.install.app.AppUpdateManager;
import com.getpebble.android.framework.install.firmware.FirmwareInstallManager;
import com.getpebble.android.framework.notification.NotificationSender;
import com.getpebble.android.framework.notification.NotificationSender.NotificationDemoType;
import com.getpebble.android.framework.notification.PblNotificationProcessor;
import com.getpebble.android.framework.pebblekit.PebbleKit;
import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.notifications.util.AndroidAppInstallListener;
import com.sun.mail.iap.Response;
import com.sun.mail.imap.protocol.ListInfo;
import com.sun.mail.smtp.SMTPMessage;
import java.lang.ref.WeakReference;
import java.util.UUID;

class PblFrameworkManager {
    private static String TAG = PblFrameworkManager.class.getSimpleName();
    private IAdapterQueryCallback mAdapterCallback;
    private AndroidAppInstallListener mAndroidAppInstallListener;
    private AppUpdateManager mAppUpdateManager;
    private IAdapterQuery mBtAdapter;
    private IDeviceConnector mBtConnection;
    private IDeviceFetcher mBtDevices;
    private IDeviceMessageSender mBtMessage;
    private ConnectionStateManager mConnectionStateManager;
    private final WeakReference<Context> mContextWeakReference;
    private DeveloperConnectionServer mDeveloperConnServer;
    private DiscoveryManager mDiscoveryManager;
    private EventSender mEventSender;
    private FirmwareInstallManager mFirmwareInstallManager;
    private FrameworkState mFrameworkState;
    private PblNotificationProcessor mNotificationProcessor;
    private NotificationSender mNotificationSender;
    private PebbleKit mPebbleKit;
    private PblPreferences mPreferences;

    private PblFrameworkManager(Context context, IDeviceConnector btConnection, IAdapterQuery btAdapter, IDeviceMessageSender btMessage, IDeviceFetcher btDevices) throws IllegalStateException, IllegalArgumentException {
        this.mContextWeakReference = new WeakReference(context);
        if (context == null) {
            throw new IllegalArgumentException("Cannot create framework with null context");
        }
        this.mBtAdapter = btAdapter;
        this.mBtConnection = btConnection;
        this.mBtMessage = btMessage;
        this.mBtDevices = btDevices;
        this.mFrameworkState = new FrameworkState(btAdapter.isDiscovering(), btAdapter.getAdapterEnabled(), new StateListener() {
            public void onStateChanged() {
                FrameworkState stateToCopy = PblFrameworkManager.this.mFrameworkState;
                if (stateToCopy == null) {
                    Trace.warning(PblFrameworkManager.TAG, "stateToCopy is null; not sending to UI");
                } else {
                    PblFrameworkManager.this.mEventSender.sendFrameworkState(new FrameworkState(stateToCopy));
                }
            }
        });
        this.mConnectionStateManager = new ConnectionStateManager(context.getMainLooper(), context, this.mBtConnection, this.mBtAdapter, this.mBtMessage, new PublicConnectionStatusUpdater(context.getContentResolver()), new ConnectionGoalUpdater(context.getContentResolver()), this.mFrameworkState);
        this.mPreferences = new PblPreferences(context);
        this.mEventSender = new EventSender();
        this.mDiscoveryManager = new DiscoveryManager(context, this.mBtDevices);
        this.mAdapterCallback = new IAdapterQueryCallback() {
            public void onAdapterStateChanged(boolean enabled) {
                PblFrameworkManager.this.mFrameworkState.setIsBluetoothEnabled(enabled);
            }

            public void onAdapterError() {
                Trace.warning(PblFrameworkManager.TAG, "onAdapterError()");
            }
        };
        this.mAppUpdateManager = AppUpdateManager.create(this.mFrameworkState);
        this.mBtAdapter.registerBluetoothAdapterCallback(this.mAdapterCallback);
        this.mFirmwareInstallManager = new FirmwareInstallManager(context);
        this.mNotificationSender = new NotificationSender(context, this.mFrameworkState);
        this.mPebbleKit = PebbleKit.getInstance(context);
        if (this.mPreferences.getBooleanData(PrefKey.DEVELOPER_CONNECTION_ACTIVE, false)) {
            Trace.debug(TAG, "Enabling developer connection based on previous state");
            this.mDeveloperConnServer = new DeveloperConnectionServer(context, this.mFrameworkState, this.mBtMessage);
            this.mDeveloperConnServer.start();
        }
        this.mNotificationProcessor = new PblNotificationProcessor(context, this.mPreferences, context.getContentResolver());
        this.mAndroidAppInstallListener = new AndroidAppInstallListener();
        DebugConnection.start(context, this.mFrameworkState);
    }

    public static PblFrameworkManager create(Context context, IDeviceConnector btConnection, IAdapterQuery btAdapter, IDeviceMessageSender btMessage, IDeviceFetcher btDevices) throws IllegalArgumentException, IllegalStateException {
        if (context == null) {
            throw new IllegalArgumentException("'context' cannot be null");
        } else if (btConnection == null) {
            throw new IllegalArgumentException("'btConnection' cannot be null");
        } else if (btAdapter == null) {
            throw new IllegalArgumentException("'btAdapter' cannot be null");
        } else if (btMessage == null) {
            throw new IllegalArgumentException("'btMessage' cannot be null");
        } else if (btDevices != null) {
            return new PblFrameworkManager(context, btConnection, btAdapter, btMessage, btDevices);
        } else {
            throw new IllegalArgumentException("'btDevices' cannot be null");
        }
    }

    public Handler getIncomingMessageHandlerWithLooper(Looper looper) {
        return new Handler(looper) {
            public void handleMessage(Message msg) {
                try {
                    doHandleMessage(msg);
                } catch (Exception e) {
                    Trace.error(PblFrameworkManager.TAG, "Exception while handling message.", e);
                }
            }

            private void doHandleMessage(Message msg) {
                Bundle data;
                PblDevice device;
                Context context;
                MessageRouter router;
                Bundle args;
                switch (msg.what) {
                    case SMTPMessage.RETURN_FULL /*1*/:
                        Trace.debug(PblFrameworkManager.TAG, "Request to connect to a device");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        } else {
                            PblFrameworkManager.this.mConnectionStateManager.requestConnectToDevice(device);
                            return;
                        }
                    case SMTPMessage.RETURN_HDRS /*2*/:
                        Trace.debug(PblFrameworkManager.TAG, "Request to disconnect from a device");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        } else {
                            PblFrameworkManager.this.mConnectionStateManager.requestDisconnectFromDevice(device);
                            return;
                        }
                    case ListInfo.INDETERMINATE /*3*/:
                        Trace.debug(PblFrameworkManager.TAG, "Set reply messenger");
                        PblFrameworkManager.this.mEventSender.setReplyMessenger(msg.replyTo);
                        PblFrameworkManager.this.mEventSender.sendFrameworkState(new FrameworkState(PblFrameworkManager.this.mFrameworkState));
                        return;
                    case SMTPMessage.NOTIFY_DELAY /*4*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to start discovery");
                        context = (Context) PblFrameworkManager.this.mContextWeakReference.get();
                        if (context == null) {
                            Trace.debug(PblFrameworkManager.TAG, "Failed to purge unknown devices due to null context");
                            return;
                        }
                        PblDeviceModel.purgeUnknownDevices(context.getContentResolver());
                        PblFrameworkManager.this.mDiscoveryManager.getBondedDevices();
                        Trace.verbose(PblFrameworkManager.TAG, "discovery started = " + PblFrameworkManager.this.mBtAdapter.startDiscovery());
                        return;
                    case R.styleable.WalletFragmentStyle_maskedWalletDetailsHeaderTextAppearance /*5*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to stop discovery");
                        PblFrameworkManager.this.mBtAdapter.cancelDiscovery();
                        return;
                    case R.styleable.WalletFragmentStyle_maskedWalletDetailsBackground /*6*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to send demo notification");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        NotificationDemoType type = (NotificationDemoType) data.getSerializable("notification_type_extra");
                        if (type == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null demo type");
                            return;
                        } else {
                            PblFrameworkManager.this.mNotificationSender.sendNotificationDemoMessage(type);
                            return;
                        }
                    case R.styleable.WalletFragmentStyle_maskedWalletDetailsButtonTextAppearance /*7*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to update firmware");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        }
                        Uri firmwareUri = (Uri) data.getParcelable("firmware_uri_extra");
                        if (firmwareUri == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null firmware uri");
                            return;
                        } else if (((Context) PblFrameworkManager.this.mContextWeakReference.get()) == null) {
                            Trace.debug(PblFrameworkManager.TAG, "Failed to install firmware due to null context");
                            return;
                        } else {
                            PblFrameworkManager.this.mFirmwareInstallManager.installFirmware(MessageRouter.getOrCreateRouter(PblFrameworkManager.this.mBtMessage, device), firmwareUri, PblFrameworkManager.this.mFrameworkState);
                            return;
                        }
                    case Response.NO /*8*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to install app");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        }
                        Uri appUri = (Uri) data.getParcelable("uri_extra");
                        if (appUri == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null app uri");
                            return;
                        }
                        boolean autoStart = data.getBoolean("auto_start_extra", false);
                        boolean allowReinstall = data.getBoolean("allow_reinstall_extra", false);
                        if (((Context) PblFrameworkManager.this.mContextWeakReference.get()) == null) {
                            Trace.debug(PblFrameworkManager.TAG, "Failed to install app due to null context");
                            return;
                        }
                        router = MessageRouter.getOrCreateRouter(PblFrameworkManager.this.mBtMessage, device);
                        args = new Bundle();
                        args.putParcelable(EndpointArgumentKeys.URI.toString(), appUri);
                        args.putBoolean(EndpointArgumentKeys.AUTO_START_APP.toString(), autoStart);
                        args.putBoolean(EndpointArgumentKeys.ALLOW_REINSTALL.toString(), allowReinstall);
                        args.putBoolean(EndpointArgumentKeys.VIBRATE.toString(), true);
                        router.onRequest(new EndpointRequest(EndpointId.APP_INSTALL_MANAGER, EndpointAction.ADD_APP, args), PblFrameworkManager.this.mFrameworkState);
                        return;
                    case R.styleable.WalletFragmentStyle_maskedWalletDetailsLogoTextColor /*9*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to uninstall app");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        }
                        String appUuidStr = data.getString("app_uuid_extra");
                        UUID appUuid = appUuidStr == null ? null : UUID.fromString(appUuidStr);
                        if (appUuid == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null app uuid");
                            return;
                        }
                        router = MessageRouter.getOrCreateRouter(PblFrameworkManager.this.mBtMessage, device);
                        args = new Bundle();
                        args.putString(EndpointArgumentKeys.UUID.toString(), appUuid.toString());
                        router.onRequest(new EndpointRequest(EndpointId.APP_INSTALL_MANAGER, EndpointAction.REMOVE_APP, args), PblFrameworkManager.this.mFrameworkState);
                        return;
                    case R.styleable.WalletFragmentStyle_maskedWalletDetailsLogoImageType /*10*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to update firmware for PRF");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        } else if (((Context) PblFrameworkManager.this.mContextWeakReference.get()) == null) {
                            Trace.debug(PblFrameworkManager.TAG, "Failed to install firmware due to null context");
                            return;
                        } else {
                            PblFrameworkManager.this.mFirmwareInstallManager.installFirmwareForRecovery(MessageRouter.getOrCreateRouter(PblFrameworkManager.this.mBtMessage, device), PblFrameworkManager.this.mFrameworkState);
                            return;
                        }
                    case R.styleable.MapAttrs_uiZoomGestures /*11*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to fetch app info from uri");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        Uri uri = (Uri) data.getParcelable("uri_extra");
                        if (uri == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null uri");
                            return;
                        }
                        context = (Context) PblFrameworkManager.this.mContextWeakReference.get();
                        if (context == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null context");
                            return;
                        } else {
                            new AppBundleManager(context).fetchAppInfoFromFile(uri, PblFrameworkManager.this.mFrameworkState);
                            return;
                        }
                    case Response.BAD /*12*/:
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        } else {
                            MessageRouter.getOrCreateRouter(PblFrameworkManager.this.mBtMessage, device).onRequest(new EndpointRequest(EndpointId.CORE_DUMP, EndpointAction.REQUEST_CORE_DUMP), PblFrameworkManager.this.mFrameworkState);
                            return;
                        }
                    case R.styleable.MapAttrs_zOrderOnTop /*13*/:
                        Trace.debug(PblFrameworkManager.TAG, "Received request for log dump");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        } else {
                            MessageRouter.getOrCreateRouter(PblFrameworkManager.this.mBtMessage, device).onRequest(new EndpointRequest(EndpointId.LOG_DUMP, EndpointAction.REQUEST_LOG_DUMP), PblFrameworkManager.this.mFrameworkState);
                            return;
                        }
                    case 14:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to start developer connection");
                        context = (Context) PblFrameworkManager.this.mContextWeakReference.get();
                        if (context == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null context");
                            return;
                        }
                        PblFrameworkManager.this.mDeveloperConnServer = new DeveloperConnectionServer(context, PblFrameworkManager.this.mFrameworkState, PblFrameworkManager.this.mBtMessage);
                        PblFrameworkManager.this.mDeveloperConnServer.start();
                        DeveloperConnectionClient.connectToServer(context, PblFrameworkManager.this.mFrameworkState, PblFrameworkManager.this.mBtMessage);
                        PblFrameworkManager.this.mPreferences.setBooleanData(PrefKey.DEVELOPER_CONNECTION_ACTIVE, true);
                        return;
                    case 15:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to stop developer connection");
                        PblFrameworkManager.this.mDeveloperConnServer.stop();
                        PblFrameworkManager.this.mDeveloperConnServer = null;
                        DeveloperConnectionClient.disconnectFromServer();
                        PblFrameworkManager.this.mPreferences.setBooleanData(PrefKey.DEVELOPER_CONNECTION_ACTIVE, false);
                        return;
                    case Response.BYE /*16*/:
                        Trace.verbose(PblFrameworkManager.TAG, "Received request to send an analytics event");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(Event.class.getClassLoader());
                        Event event = (Event) data.getParcelable("analytics_event_extra");
                        if (event == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null analytics event");
                            return;
                        } else {
                            AnalyticsLogger.logEvent(event.getEventCollection(), event.getEventParams());
                            return;
                        }
                    case 17:
                        AnalyticsLogger.uploadAnalytics();
                        return;
                    case 18:
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        } else {
                            AnalyticsLogger.setActive(data.getBoolean("analytics_enable_extra"));
                            return;
                        }
                    case 19:
                        context = (Context) PblFrameworkManager.this.mContextWeakReference.get();
                        Context appContext = null;
                        if (context != null) {
                            appContext = context.getApplicationContext();
                        }
                        if (appContext != null) {
                            try {
                                AnalyticsLogger.reinitialize(AnalyticsLogger.createConfig(appContext));
                                return;
                            } catch (InitializationException e) {
                                Trace.error(PblFrameworkManager.TAG, "Failed to reinitialize analytics.", e);
                                return;
                            } catch (IllegalStateException e2) {
                                Trace.error(PblFrameworkManager.TAG, "Failed to reinitialize analytics.", e2);
                                return;
                            }
                        }
                        return;
                    case 20:
                        if (PblFrameworkManager.this.mPreferences.getBooleanData(PrefKey.DEVELOPER_CONNECTION_ACTIVE, false)) {
                            Trace.debug(PblFrameworkManager.TAG, "Received request to ping the developer connection proxy");
                            context = (Context) PblFrameworkManager.this.mContextWeakReference.get();
                            if (context == null) {
                                Trace.warning(PblFrameworkManager.TAG, "Null context");
                                return;
                            } else {
                                DeveloperConnectionClient.ping(context, PblFrameworkManager.this.mFrameworkState, PblFrameworkManager.this.mBtMessage);
                                return;
                            }
                        }
                        return;
                    case 21:
                        Trace.debug(PblFrameworkManager.TAG, "Received request to install a file on Pebble");
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        }
                        data.setClassLoader(PblDevice.class.getClassLoader());
                        device = (PblDevice) data.getParcelable("device_extra");
                        if (device == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null device");
                            return;
                        }
                        Uri fileUri = (Uri) data.getParcelable("uri_extra");
                        if (fileUri == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null file uri");
                            return;
                        }
                        String fileName = data.getString("file_name_extra");
                        String isoLocale = data.getString("iso_locale_extra");
                        int languageVersion = data.getInt("language_version_extra");
                        if (((Context) PblFrameworkManager.this.mContextWeakReference.get()) == null) {
                            Trace.debug(PblFrameworkManager.TAG, "Failed to install file due to null context");
                            return;
                        }
                        router = MessageRouter.getOrCreateRouter(PblFrameworkManager.this.mBtMessage, device);
                        args = new Bundle();
                        args.putParcelable(EndpointArgumentKeys.URI.toString(), fileUri);
                        args.putString(EndpointArgumentKeys.FILE_NAME.toString(), fileName);
                        args.putString(EndpointArgumentKeys.ISO_LOCALE.toString(), isoLocale);
                        args.putInt(EndpointArgumentKeys.LANGUAGE_VERSION.toString(), languageVersion);
                        router.onRequest(new EndpointRequest(EndpointId.FILE_INSTALL_MANAGER, EndpointAction.ADD_FILE, args), PblFrameworkManager.this.mFrameworkState);
                        return;
                    case 22:
                        data = msg.getData();
                        if (data == null) {
                            Trace.warning(PblFrameworkManager.TAG, "Null bundle");
                            return;
                        } else {
                            AndroidLogger.setVerboseLogcat(data.getBoolean("logcat_verbose_extra", false));
                            return;
                        }
                    case 23:
                        Trace.verbose(PblFrameworkManager.TAG, "Received request to do connection state processing");
                        PblFrameworkManager.this.mConnectionStateManager.requestStateProcessing();
                        return;
                    default:
                        super.handleMessage(msg);
                        return;
                }
            }
        };
    }

    public FrameworkState getState() {
        return this.mFrameworkState;
    }

    public void destroy() {
        DebugConnection.stop();
        this.mPreferences = null;
        this.mEventSender = null;
        this.mBtConnection = null;
        this.mBtDevices = null;
        this.mFrameworkState.setStateListener(null);
        this.mFrameworkState = null;
        this.mFirmwareInstallManager = null;
        this.mNotificationSender = null;
        this.mBtMessage = null;
        this.mConnectionStateManager.destroy();
        this.mConnectionStateManager = null;
        this.mDiscoveryManager.destroy();
        this.mDiscoveryManager = null;
        this.mPebbleKit.destroy();
        this.mPebbleKit = null;
        this.mBtAdapter.unregisterBluetoothAdapterCallback(this.mAdapterCallback);
        this.mAdapterCallback = null;
        this.mBtAdapter = null;
        if (this.mDeveloperConnServer != null) {
            this.mDeveloperConnServer.stop();
            this.mDeveloperConnServer = null;
        }
        this.mNotificationProcessor.destroy();
        this.mAndroidAppInstallListener.destroy();
    }
}
